<?php

namespace Aiweline\AiReviewForMagentoProduct\Cron\Magento;

use Aiweline\AiReviewForMagentoProduct\Helper\Config;
use Weline\Cron\CronTaskInterface;
use Weline\Framework\Manager\ObjectManager;

class AiReviewGeneration implements CronTaskInterface
{

    function __construct(
        private Config $config,
    )
    {

    }

    /**
     * @inheritDoc
     */
    function name(): string
    {
        return '每天生成评论到Magento';
    }

    /**
     * @inheritDoc
     */
    function execute_name(): string
    {
        return 'AiReviewForMagento';
    }

    /**
     * @inheritDoc
     */
    function tip(): string
    {
        return 'AI生成评论到Magento';
    }

    /**
     * @inheritDoc
     */
    function cron_time(): string
    {
        return '0 0 * * *';
    }

    /**
     * @inheritDoc
     */
    function execute(): string
    {
        $store_id = $this->config->get('store_id');
//        $command = PHP_BINARY . ' bin/w magento:review --store_id=' . $store_id;
        /** @var \Aiweline\AiReviewForMagentoProduct\Console\Magento\Review $console */
        $console = ObjectManager::getInstance(\Aiweline\AiReviewForMagentoProduct\Console\Magento\Review::class);
        $res = $console->execute(['store_id' => $store_id]);
        return $res;
    }

    /**
     * @inheritDoc
     */
    public function unlock_timeout(int $minute = 30): int
    {
        return 60;
    }
}